package com.etc.game;

import java.awt.*;

public class GameObject {

    //图片
    Image img;

    //物体的坐标
    double x,y;

    //物体的宽度和高度
    int width,height;

    //物体的移动速度
    int speed;


    //绘制图像
    public void drawMySelf(Graphics g){
        g.drawImage(this.img,(int)this.x,(int)this.y,null);

    }


    public GameObject(Image img, double x, double y) {
        this.img = img;
        this.x = x;
        this.y = y;
        if (img != null){
            this.width = img.getWidth(null);
            this.height = img.getHeight(null);
        }
    }


    public GameObject(Image img, double x, double y, int width, int height, int speed) {
        this.img = img;
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
        this.speed = speed;
    }


    public GameObject() {
    }


    /**
     * 返回物体对应矩形区域，便于后续在碰撞检测中使用
     * @return
     */
    public Rectangle getRect(){
        return  new Rectangle((int)x,(int) y, width, height);
    }
}
